package inutan.login;

import inutan.login.controller.CommonController;
import inutan.login.controller.LoginController;
import org.ricks.boot.AbstractBootstrap;
import org.ricks.boot.Scan;
import org.ricks.common.ModularContext;
import org.ricks.common.conf.RicksPropertiesLoader;
import org.ricks.common.exception.ServerBootstrapException;
import org.ricks.net.http.HttpBootstrap;
import org.ricks.net.http.RestfulHandler;
import org.ricks.orm.OrmContext;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

public class LoginBootstrap extends AbstractBootstrap {

    @Override
    public void startBefore() {
        ModularContext.me().scan(Set.of("inutan.login","inutan.common.config.datasource","inutan.common.entity"));
    }

    @Override
    protected void onStart() {
        //初始化ORM
//        OrmContext.me().init();

        RestfulHandler restfulHandler = new RestfulHandler();
        restfulHandler.addController(LoginController.class);
        restfulHandler.addController(CommonController.class);
        HttpBootstrap bootstrap = new HttpBootstrap().setPort(8080);
        bootstrap.httpHandler(restfulHandler);
        bootstrap.configuration()
                .threadNum(Runtime.getRuntime().availableProcessors())
                .readBufferSize(1024 * 4)
                .writeBufferSize(1024 * 4)
                .readMemoryPool(16384 * 1024 * 4)
                .writeMemoryPool(10 * 1024 * 1024 * Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors()).debug(false);
        bootstrap.start();
    }

    @Override
    protected void onStop() {
        //销毁ORM
//        OrmContext.me().shutdown();
    }
}
